package com.gao.id.support.segment;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LeafAllocServiceImpl implements LeafAllocService {

    @Autowired
    private LeafAllocMapper leafAllocMapper;

    /**
     * 获取所有的 ID 信息
     * @return
     */
    @Override
    public List<LeafAlloc> getAllLeafAllocs() {
        return leafAllocMapper.getAllLeafAllocAllocs();
    }

    /**
     * 更新当前业务 key 的最大 ID
     * @param tag
     * @return
     */
    @Override
    public LeafAlloc updateMaxIdAndGetLeafAlloc(String tag) {
        leafAllocMapper.updateMaxId(tag);
        return leafAllocMapper.getLeafAlloc(tag);
    }

    /**
     * 更新最大 ID (自定义步长)
     * @param leafAlloc
     * @return
     */
    @Override
    public LeafAlloc updateMaxIdByCustomStepAndGetLeafAlloc(LeafAlloc leafAlloc) {
        leafAllocMapper.updateMaxIdByCustomStep(leafAlloc);
        return leafAllocMapper.getLeafAlloc(leafAlloc.getKey());
    }

    /**
     * 获取所有业务 key
     * @return
     */
    @Override
    public List<String> getAllTags() {
        return leafAllocMapper.getAllTags();
    }
}
